<?php
	include_once 'InterfaceDAO.php';
	include_once "BMetier/Participation.class.php";
	
	class ParticipationDAO {

		public static function store(Participation $participation) {
			if($participation != null) {
				if($participation->getId() == null) {
					$req = "Insert into participation set friday =". $participation->getFriday() .", ";
					$req .= "saturday=". $participation->getSaturday().", ";
					$req .= "sunday=". $participation->getSunday();
					@mysql_query($req) or die('ERROR : Insert participation' . $req);
					$participation->setId(intval(mysql_insert_id()));
				}else {
					$req = "Update participation set friday =". $participation->getFriday() .", ";
					$req .= "saturday=". $participation->getSaturday().", ";
					$req .= "sunday=". $participation->getSunday()." ";
					$req .= "where id = " . $participation->getId();
					@mysql_query($req) or die('ERROR : Update participation ' . $req);
				}
				return $participation;
			}
		}

		public static function delete(Participation $participation){
			if($participation != null) {
				if($participation->getId() != null) {
					$req = "Delete From participation where id = " . $participation->getId();
					@mysql_query($req) or die('ERROR : delete participation' . $req);
				}
			}
		}

		public static function load($id) {
			if($id != null) {
				$req = "Select id, friady, saturday, sunday From participation where id = " . $id;
				$res = @mysql_query($req) or die('ERROR : Select participation ' . $req);
				if (mysql_num_rows($res) == 0) {
					return ;
				}

				$participation = new Participation();
 				while($row = mysql_fetch_assoc($res)){
   					$participation->setId(intval($row['id']));
   					$participation->setFriday(intval($row['friday']));
   					$participation->setSaturday(intval($row['saturday']));
   					$participation->setSunday(intval($row['sunday']));
				}
				return $album;
			}
		}
	}
?>